﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ArkanoidX
{
    public class Debug
    {
        public static string SourceName = "AndroidX";

        public static TraceSource MainSource = new TraceSource(SourceName, SourceLevels.Information);
        public static SourceSwitch Switch = new SourceSwitch(SourceName);

        public static TraceListener Listener = new DefaultTraceListener();
        public static EventTypeFilter Filter = new EventTypeFilter(SourceLevels.All);

        static Debug()
        {
            MainSource.Switch = Switch;
            MainSource.Switch.Level = SourceLevels.All;
            MainSource.Listeners.Clear();
            MainSource.Listeners.Add(Listener);

            Listener.Filter = Filter;

            MainSource.Switch.Level = SourceLevels.Critical;
            Filter.EventType = SourceLevels.Critical;
        }

        public static void TraceInformation(String message)
        {
            MainSource.TraceInformation(message);
        }

        public static void SetSwitch(SourceLevels level)
        {
            /*
             * only level specified by level and above are traced and sent to listeners
             */
            MainSource.Switch.Level = level;
        }

        public static void SetFilter(SourceLevels level)
        {
            Filter.EventType = level;
        }

        public static void WriteLine(string message, TraceEventType evType)
        {
            message = String.Format("{0}: {1}", DateTime.Now.ToLongTimeString(), message);
            MainSource.TraceEvent(evType, 0, message);
        }
    }
}
